<?php
class ManageAction extends BaseAction {

	public function _initialize() {
        	parent::_initialize();
    }
	public function index() {
		if(!$_SESSION['mid']){//判断是否登录
			// 记录登陆前的url地址
			$_SESSION['refer_url'] = U('enterprise/Manage/index');
			redirect(U('home/Public/login'));
		}
		$this->assign('_header_tab_on_manage',1);
		$this->display();

    }
	public function add($corp_id=0) {
		$this->assign('_header_tab_on_manage',1);
		$this->display();
    }
	public function dosave() {
		$this->isAjax();

		$_POST['corp_name_cn'] = t($_POST['corp_name_cn']);
 		$_POST['corp_name_en'] = t($_POST['corp_name_en']);

 		$_POST['corp_desc'] = t($_POST['corp_desc']);
		if(empty($_POST['corp_name_cn']) && empty($_POST['corp_name_en'])) {
            $this->error( "品牌的中文名称或英文名称必须要有一个！" );
        }
		$data = $_POST;
		if(intval($_POST['corp_id'])){
			$data['corp_updatetime'] = time();
			$data['corp_updateuser'] = $this->mid;
			$r = M( 'CorpBase' )->save($data);
		}else{
			if($this->mid){
				$isu = 'member';
				if($data['corp_is_owner']){
					$data['corp_owner'] = $this->mid;
				}
			}else{
				$isu = 'anonymous';
			}
			$data['corp_status'] = in_array($isu,$this->_opt['autoactive'])?1:0;
			$data['corp_addtime'] = time();
			$data['corp_adduser'] = $this->mid;
			$data['corp_updatetime'] = time();
			$data['corp_updateuser'] = $this->mid;
			$data['corp_addip'] = getIP();
			$r = M( 'CorpBase' )->add($data);
		}
		if( $r ) {
			$this->assign('jumpUrl', U('enterprise/Manage/index',array('id'=>$r)));
			$this->success('添加成功');
		}else {
			$this->error( "添加失败" );
		}
	}


}
